﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GasData
{
    public partial class GasInfo
    {
        /* Constructors */
        public GasInfo()
        {
            gas_name = "Unknown";
            cur_val = 0.0;
            max = 0.0;
            min = 0.0;
            average = 0.0;
            variance = 0.0;
            sample_count = 0;
        }

        public GasInfo(GasInfo new_gas_info)
        {
            gas_name = new_gas_info.Gas_name;
            cur_val = new_gas_info.Cur_val;
            max = new_gas_info.Max;
            min = new_gas_info.Min;
            average = new_gas_info.Average;
            variance = new_gas_info.Variance;
            sample_count = new_gas_info.Sample_count;
        }

        public int Sample_count
        {
            get
            {
                return sample_count;
            }
            set
            {
                sample_count = value;
            }
        }

        public String Gas_name
        {
            get
            {
                return gas_name;
            }
            set
            {
                gas_name = value;
            }
        }

        public double Cur_val
        {
            get
            {
                return cur_val;
            }
            set
            {
                cur_val = value;
            }
        }

        public double Max
        {
            get
            {
                return max;
            }
            set
            {
                max = value;
            }
        }

        public double Min
        {
            get
            {
                return min;
            }
            set
            {
                min = value;
            }
        }

        public double Average
        {
            get
            {
                return average;
            }
            set
            {
                average = value;
            }
        }

        public double Variance
        {
            get
            {
                return variance;
            }
            set
            {
                variance = value;
            }
        }

        /* Public methods */
        public void UpdateGasInfo(double new_cur_val){
            cur_val = new_cur_val;
            max = GetBigger(max,new_cur_val);
            min = GetSmaller(min,new_cur_val);
            average = GetMean(new_cur_val);
            sample_count++;
        }

        /* Private methods */
        private double GetBigger(double a, double b){
            return a > b ? a : b;
        }

        private double GetSmaller(double a, double b)
        {
            return a > b ? b : a;
        }

        private double GetMean(double new_data_sample)
        {
            return (average * sample_count + new_data_sample) / (sample_count + 1);
        }

        /* Internal data */
        private String gas_name;
        private double cur_val;
        private double max;
        private double min;
        private double average;
        private double variance;
        private int sample_count;

    }
}
